package com.wsz.eduorder.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wsz.commonutils.OrderNoUtil;
import com.wsz.commonutils.ordervo.CourseUtils;
import com.wsz.commonutils.ordervo.MemberUtils;
import com.wsz.eduorder.client.EduClient;
import com.wsz.eduorder.client.UcenterClient;
import com.wsz.eduorder.pojo.Order;
import com.wsz.eduorder.service.OrderService;
import com.wsz.eduorder.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
* @author wangs
* @description 针对表【t_order(订单)】的数据库操作Service实现
* @createDate 2022-10-05 19:21:45
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
    implements OrderService{

    @Autowired
    private EduClient eduClient;

    @Autowired
    private UcenterClient ucenterClient;

    @Override
    public String createOrder(String courseId, String memberIdByJwtToken) {

        CourseUtils courseDto = eduClient.getCourseInfoOrder(courseId);

        MemberUtils ucenterMember = ucenterClient.getMemberInfoOrder(memberIdByJwtToken);

        Order order = new Order();
        String s = OrderNoUtil.getOrderNo();
        order.setOrderNo(s);
        order.setCourseId(courseId);
        order.setCourseTitle(courseDto.getTitle());
        order.setCourseCover(courseDto.getCover());
        order.setTeacherName(courseDto.getTeacherName());
        order.setTotalFee(courseDto.getPrice());
        order.setMemberId(memberIdByJwtToken);
        order.setMobile(ucenterMember.getMobile());
        order.setNickname(ucenterMember.getNickname());

        order.setStatus(0);//支付状态
        order.setPayType(1);//支付类型

        baseMapper.insert(order);

        return s;
    }
}




